Attribute VB_Name = "MGlobals"
''' VBA Code Documentor 5.0 by Rob Bovey, copyright 1996-2004,
''' all rights reserved. May be redistributed for free,
''' but may not be sold without the author's explicit permission.
Option Explicit
Option Private Module

''' **************************************************************************
''' Global Constant Declaractions Follow
''' **************************************************************************
''' Application identification constants.
Public Const gszAPP_TITLE As String = "VBA Code Documentor"
Public Const gszVERSION As String = "5.0"
Public Const gszBUILD As String = ".04"
Public Const gszAPP_MENU As String = "Document P&roject"

''' Error handling constants.
Public Const gbDEBUG_MODE As Boolean = True    ''' Debug mode indicator.
Public Const glHANDLED_ERROR As Long = 9999     ''' Indicates an error we raised.
Public Const glLONG_FUNCTION_ERROR As Long = -1 ''' Used with functions that return long values to indicate an error.
Public Const gszSILENT_ERROR As String = "XXX"  ''' Used to indicated to the top level error handler that it should not display the error.

''' Filename constants.
Public Const gszFILE_REPORT_PREFIX As String = "Report - "

''' Sheet name constants.
Public Const gszSHEET_SUMMARY As String = "Project Summary"
Public Const gszSHEET_DETAIL As String = "Project Details"

''' wksProgramData Named range constants.
Public Const gszRNG_OPEN_BOOKS As String = "OpenBooks"
Public Const gszRNG_NUM_BOOKS As String = "NumBooks"
Public Const gszRNG_BOOK_LIST_START As String = "BookListStart"

''' Error message constants
Public Const gszERR_NO_PROJECTS As String = "There are no open projects to document."
Public Const gszERR_FILE_NOT_SAVED As String = "The report workbook has not been saved."
Public Const gszERR_VBPROJ_PROTECT As String = "Your version of Excel appears to have VB Project Protection enabled. The Code Documentor cannot run with this setting. To solve this problem please take the following steps:" & vbLf & vbLf & _
    "1) Choose Tools > Macro > Security from the Excel menu." & vbLf & _
    "2) In the Security dialog select the Trusted Sources tab." & vbLf & _
    "3) Check the 'Trust access to Visual Basic Project' checkbox."

''' User message constants.
Public Const gszMSG_FILE_OVERWRITE As String = "A report file for this workbook already exists. Do you want to overwrite it with a new one?"
Public Const gszMSG_FILE_ALREADY_OPEN As String = "A report file for this workbook is already open. Please use the next dialog to save the new report file."

''' Status bar message constants
Public Const gszSTATUS_STARTUP As String = "Loading the VBA Code Documentor"
Public Const gszSTATUS_CREATING_REPORT As String = "Creating report workbook."
Public Const gszSTATUS_ENUMERATING_CONTENTS As String = "Enumerating the contents of |"
Public Const gszSTATUS_REPORT_GENERATOR As String = "Creating project summary report"
Public Const gszSTATUS_SAVING_REPORT As String = "Saving project report workbook"

''' Summary report constants
Public Const gszSUMMARY_TITLE As String = "Project Summary for | created - |"

''' Misc. constants.
Public Const glMAX_PATH As Long = 260           ''' Maximum DOS path specification length.
Public Const gszTOKEN As String = "|"           ''' String replacement token for szSubstituteText.
Public Const gszREM As String = "Rem"
Public Const gszEMPTY_STRING = ""
Public Const gszBANG As String = "!"
Public Const gszSEP As String = "\"
Public Const gszDOT As String = "."
Public Const gszDQ As String = """"
Public Const gszSQ As String = "'"
Public Const gszCONTINUED As String = " _"


''' **************************************************************************
''' Module Type Declaractions Follow
''' **************************************************************************
''' Holds the counts of various items for the entire project.
Public Type GLOBAL_ITEM_COUNTS
    lCodeModules As Long
    lClassModules As Long
    lUserForms As Long
    lDocObjects As Long
    lProcedures As Long
    lDLLDeclarations As Long
    lCodeLines As Long
    szBookName As String
End Type

''' Holds the statistics for a specific VBComponent.
Public Type COMPONENT_SPECS
    modCodeModule As CodeModule
    lProcedures As Long
    lDLLDeclarations As Long
    lCodeLines As Long
    szName As String
    szType As String
    dFileSize As Double
End Type


''' **************************************************************************
''' Global Variable Declarations Follow
''' **************************************************************************
Public guComponentSpecs() As COMPONENT_SPECS    ''' Holds details about each VBComponent.
Public guProjectInfo As GLOBAL_ITEM_COUNTS      ''' Holds details about the project as a whole.
Public glDetailOffset As Long                   ''' The current write position in the detail worksheet of the report workbook.
Public gszErrMsg As String                      ''' Used to pass error messages between procedures.
Public gszTempPath As String                    ''' The temp folder used to stored working files.


''' *************************************************************************
''' Global DLL Declarations Follow
''' *************************************************************************
Private Declare Function GetTempPathA Lib "kernel32" (ByVal nBufferLength As Long, ByVal lpBuffer As String) As Long


''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
''' Comments:   This routine initializes application global variables.
'''
''' Date        Developer           Action
''' --------------------------------------------------------------------------
''' 01/11/00    Rob Bovey           Created
''' 06/09/04    Rob Bovey           Modified the application to use the temp
'''                                 path instead of this workbook's path as the
'''                                 working directory.
'''
Public Sub InitGlobals()

    Dim uTemp As GLOBAL_ITEM_COUNTS
    Dim lBufferLength As Long
    Dim lReturnLength As Long
    Dim szBuffer As String
    Dim szAppPath As String
    
    ''' Get the temp directory.
    lBufferLength = glMAX_PATH
    szBuffer = String$(lBufferLength, vbNullChar)
    lReturnLength = GetTempPathA(lBufferLength, szBuffer)
    If lReturnLength = 0 Then
        ''' There was an error getting the temp path. Use the application path instead.
        szAppPath = ThisWorkbook.Path
        If Right$(szAppPath, 1) <> gszSEP Then szAppPath = szAppPath & gszSEP
        gszTempPath = szAppPath
    Else
        gszTempPath = Left$(szBuffer, lReturnLength)
        If Right$(gszTempPath, 1) <> gszSEP Then gszTempPath = gszTempPath & gszSEP
    End If
    
    ''' Initialize global variables.
    Erase guComponentSpecs()
    guProjectInfo = uTemp
    glDetailOffset = 0
    
End Sub

